<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('修改配置信息')}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <form class="form-horizontal m" id="form-profile-edit">
        <input id="modelType" th:value="${modelType}" type="hidden"/>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">合作者身份（PID）</label>
            <div class="col-sm-6">
                <input id="partnerId" name="partnerId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">安全校验码（key）</label>
            <div class="col-sm-6">
                <input id="payKey" name="payKey" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">商家邮箱（email）</label>
            <div class="col-sm-6">
                <input id="sellerEmail" name="sellerEmail" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">商家</label>
            <div class="col-sm-6">
                <select name="status" id="status"  class="form-control m-b">
                    <option value="0">企业</option>
                    <option value="1">个人</option>
                </select>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3"></label>
            <div class="col-sm-6">
                <button type="button" class="btn btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-danger" onclick="window.parent.layer.closeAll()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<script type="text/javascript">

    var prefix = "/profile";

    $(function () {
        $("#partnerId").val("[[${websiteProfile.get('partnerId')}]]");
        $("#payKey").val("[[${websiteProfile.get('payKey')}]]");
        $("#sellerEmail").val("[[${websiteProfile.get('sellerEmail')}]]");
        $("#status").val("[[${websiteProfile.get('status')}]]");
    })

    function submitHandler() {
        var modelType = $("#modelType").val();
        if ($.validate.form()) {
            var baseInfo = {};
            var formArray = $("#form-profile-edit").serializeArray();
            $.each(formArray,function(i,item){
                baseInfo[item.name] = item.value;
            });
            var description = JSON.stringify(baseInfo);
            $.post(prefix + "/save.json",{"type":modelType,"description":description},function (json) {
                console.log(json)
                if(json.code === 0){
                    window.parent.layer.closeAll();
                }
            })
        }
    }

</script>
</body>
</html>